﻿Imports System.IO

Partial Class Paginas_ListadoAsistentesEventos
    Inherits System.Web.UI.Page

#Region "Funciones y Procedimientos de la Pagina"
    Private Sub CargarInfo()
        Dim objNegEven As New dllNegocio.NegEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objEven As New dllEntidades.clsEventos
        Dim CantidadDisponible As String = "0"
        Try
            myCollect = objNegEven.ListarEventos(Me.hdnIdEvento.Value.Trim, "", 0)
            If myCollect.Count > 0 Then
                objEven = myCollect.Item(1)
                Me.lblEvento.Text = objEven.Nombre
                Me.lblFecHoraIni.Text = objEven.FechaHoraInicioPublicacion.ToString
                Me.lblFecHoraFin.Text = objEven.FechaHoraFinPublicacion.ToString
                Me.lblLugar.Text = objEven.Lugar
                cantidaddisponible = objEven.EntradasDisponibles
            End If
        Catch ex As Exception
        Finally
            objNegEven.Dispose()
            objNegEven = Nothing
            myCollect = Nothing
        End Try

        Dim objNegInformes As New dllNegocio.NegInformes(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Try
            myCollect = objNegInformes.ListaAsistentesPorEvento(objEven)
            Me.lblNumAsis.Text = myCollect.Count.ToString.Trim & " / " & CantidadDisponible
            Me.GrillaResultados.DataSource = myCollect
            Me.GrillaResultados.DataBind()
            If myCollect.Count > 0 Then
                Me.btnExportar.Visible = True
            End If
        Catch ex As Exception
        Finally
            objNegInformes.Dispose()
            objNegInformes = Nothing
        End Try

        objEven.Dispose()
        objEven = Nothing
    End Sub
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.hdnIdEvento.Value = Request.QueryString("EventoID")
            Me.btnExportar.Visible = False
            Call CargarInfo()
        End If
    End Sub

    Protected Sub btnVolver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Response.Redirect("ListarEventos.aspx?PostBack=SI")
    End Sub

    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportar.Click
        Dim sb As StringBuilder = New StringBuilder()
        Dim sw As StringWriter = New StringWriter(sb)
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
        Dim pagina As Page = New Page
        Dim form = New HtmlForm
        Me.GrillaResultados.EnableViewState = False
        pagina.EnableEventValidation = False
        pagina.DesignerInitialize()
        pagina.Controls.Add(form)
        form.Controls.Add(Me.GrillaResultados)
        pagina.RenderControl(htw)
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "attachment;filename=" & Me.lblEvento.Text.Trim & ".xls")
        Response.Charset = "UTF-8"
        Response.ContentEncoding = Encoding.Default
        Response.Write(sb.ToString())
        Response.End()
    End Sub
End Class
